package io.github.libo.alg.sort;

import io.github.libo.util.ArrayUtil;

import java.util.List;

/**
 * @author libo
 * @date 2020/3/10
 * 选择排序
 */
public class SelectSort implements SortStrategy<Integer> {

    @Override
    public Integer[] sort(Integer[] numbers) {
        for(int i=0; i< numbers.length - 1; i++){
            int minIndex = i;
            int min = numbers[i];
            for(int j= i; j < numbers.length; j++){
                if(numbers[j] < min){
                    minIndex = j;
                    min = numbers[j];
                }
            }

            ArrayUtil.swap(i, minIndex, numbers);
        }

        return numbers;
    }
}
